package com.easy.dfc.service;

import com.easy.dfc.Utils.PagingUtil;
import com.easy.dfc.mapper.EnrolltuangouMapper;
import com.easy.dfc.mapper.TuangouMapper;
import com.easy.dfc.entity.Enrolltuangou;
import com.easy.dfc.entity.Stock;
import com.easy.dfc.entity.TuangouWithBLOBs;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by VULCANTSeries on 2017/5/24.
 */
@Service
public class TuangouService {

    @Resource
    private TuangouMapper tuangouMapper;

    @Resource
    private EnrolltuangouMapper enrolltuangouMapper;

    //根据当前时间选出还在活动时间内的活动
    public List<TuangouWithBLOBs> getTuangouList(PagingUtil pagingUtil) {
        List<TuangouWithBLOBs> tuangouWithBLOBsList = tuangouMapper.selectAll(pagingUtil);
        return tuangouWithBLOBsList;
    }

    //根据传入时间筛选活动
    public List<TuangouWithBLOBs> getTuangouInTime(PagingUtil pagingUtil) {
        List<TuangouWithBLOBs> tuangouWithBLOBsList = tuangouMapper.selectInTime(pagingUtil);
        return tuangouWithBLOBsList;
    }

    //根据BrandId选出还在活动时间内的活动
    public List<TuangouWithBLOBs> selectByBrandNow(PagingUtil pagingUtil) {
        List<TuangouWithBLOBs> tuangouWithBLOBsList = tuangouMapper.selectByBrandNow(pagingUtil);
        return tuangouWithBLOBsList;
    }

    //根据BrandId选出往期的活动
    public List<TuangouWithBLOBs> selectByBrandBefore(PagingUtil pagingUtil) {
        List<TuangouWithBLOBs> tuangouWithBLOBsList = tuangouMapper.selectByBrandBefore(pagingUtil);
        return tuangouWithBLOBsList;
    }

    //根据FactoryId选出还在活动时间内的活动
    public List<TuangouWithBLOBs> selectByFactoryNow(PagingUtil pagingUtil) {
        List<TuangouWithBLOBs> tuangouWithBLOBsList = tuangouMapper.selectByFactoryNow(pagingUtil);
        return tuangouWithBLOBsList;
    }

    //根据FactoryId选出还在活动时间内的活动
    public List<TuangouWithBLOBs> selectByFactoryNowFor3(PagingUtil pagingUtil) {
        List<TuangouWithBLOBs> tuangouWithBLOBsList = tuangouMapper.selectByFactoryNowFor3(pagingUtil);
        return tuangouWithBLOBsList;
    }

    //根据productId获取产品信息
    public List<TuangouWithBLOBs> getTuangou(String ProductId) {
        List<TuangouWithBLOBs> tuangouWithBLOBs = tuangouMapper.selectByProductId(ProductId);
        return tuangouWithBLOBs;
    }

    //根据ProductId返回库存、
    public Stock stockCheck(String ProductId) {
        Stock stock = tuangouMapper.stockCheck(ProductId);
        return stock;
    }

    //添加新活动
    public int insertSelective(TuangouWithBLOBs TuangouWithBLOBs) {
        return tuangouMapper.insertSelective(TuangouWithBLOBs);
    }

    //查出该活动已购买数量
    public Enrolltuangou selectNumByTuangouId(int tuangouId) {
        return enrolltuangouMapper.selectNumByTuangouId(tuangouId);
    }

    //购买
    public int insertSelective(Enrolltuangou enrolltuangou) {
        return enrolltuangouMapper.insertSelective(enrolltuangou);
    }
}
